<?php 


include_once('commonfuncs.php');

  function sendcontact(){

 $Email = stripslashes($_POST['Email']); 
  $Comment = stripslashes($_POST['Comment']); 
  if($_POST['Email']){
  // validation
  
  $validationOK=true;
  if ($Email==""){ $validationOK=false;}
  if ($Comment=="") {$validationOK=false;}
  if (!$validationOK) {
   error("Make sure all fields are filled");
  }else{
  
  // prepare email body text
  $Body = "";
  $Body .= "Email: ";
  $Body .= $Email;
  $Body .= "\n";
  $Body .= "Comment: ";
  $Body .= $Comment;
  $Body .= "\n";
  $EmailTo = emailaddres;
  $Subject = "stream4u.eu contact form";
  // send email 
  
  $headers = 'From: $Email' . "\r\n" .
	  'Reply-To: $Email' . "\r\n" .
	  'X-Mailer: PHP/' . phpversion();
  
  $success  = mail($EmailTo, $Subject, $Body, $headers);
  
  
  // redirect to success page 
  if ($success){
	 good("An email was sent to the admin. You will be contacted shortly. Thank you for your feedback.");
	 
	 }
  else{
   error("Email was not sent!");
  }
  }}}
  
  
  
  	
	function createwebsite(){
			

	if($_POST['websitead']){global $db;
dbconnect();
	$check = check_empty($_POST['websitename'] , "Enter website name", $check);	
	if($_POST['websitename']){
	$filterdomain = array("www","http://","https://", "/",",");
	foreach($filterdomain as $f){
		
	if(stristr($_POST['websitename'],$f)){
		error("Enter the proper URL format like 'example.com'. Enter only on website at a time. Dont add www"); $check =1 ;
		break;
		}
		
		}
	
	//if (!preg_match("/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i",$_POST['websitename'])) {
		//error("Enter the proper URL format like 'example.com'. Enter only on website at a time"); $check =1 ;
		//}	
		}
	if($check != "1"){
			
			$data6['website_wl'] = $_POST['websitename'];
			$data6['user_wl'] = $_SESSION['user'];
			$db->query_insert("websitelist_wl", $data6);
			good("Added successfully!");
			}
	
	}
	
		}
		
		function getchanneldetails($id){
		global $db;
dbconnect();

$sql = "SELECT * FROM stream_stm where id_stm = $id";
return $record = $db->query_first($sql); 

		
		}	
		
		
function createchannel(){
	
	

	if(!empty($_POST['createchannel'])){	
		global $db;
		dbconnect();
		$check = check_empty($_POST['streamname'] , "Enter channel name", $check);	
	
	
	
	if($_POST['streamname']){
		$streamm = $db->escape($_POST[streamname]);	
$sql2 = "select u_stm from stream_stm where u_stm = '$streamm'";
$row = $db->query_first($sql2);

if (preg_match("@[^a-zA-Z0-9 ]@", $_POST['streamname'])) {
 error("Channel name should only be numbers and alphabets");
		 $check ="1";

} 

if($_POST['protect']){
	$filterdomain = array("www","http://","https://", "/");
	foreach($filterdomain as $f){
		
	if(stristr($_POST['protect'],$f)){
		error("Enter the proper URL format like 'example.com'. Enter only on website at a time. Dont add www"); $check =1 ;
		break;
		}
	}}
	
if ($row['u_stm']){
		 error("This channel is already present in our database.");
		 $check ="1";
		}







	}
if($check != "1"){
	
		$data6['u_stm'] = $_POST['streamname'];
			$data6['protect_stm'] = $_POST['protect'];
			$data6['p_stm'] = uniqid();
			$data6['date_stm'] = "NOW()";
			$data6['is_active_stm'] = 3;
			$data6['viewers'] = 0;
	$ids = $db->query_insert("stream_stm", $data6);
redirect("?p=viewchannel&id=$ids");
	
	}
	}
	}			
			
			
				  
	function getChannels() {
		global $db;
		dbconnect();

		$sql = "select * from channels";
		$rows = $db->query($sql);
		while ($record= $db->fetch_array($rows)) {
			var_dump($record);
			echo '<tr>'
					+ '<td>'. $record['name'] .'/td>'
					+ '<td valign="middle" align="right" width="10" height="10" >' . $record['name'] .'</td>'
				+ '</tr>';

	  		//echo "<div class='left_channel'>$record[website_wl]</div><div class='right_channel'><a href='?p=website&id=$record[id_wl]&s=del'> Delete</a></div>";
		}
	}